#include <algorithm>
#include <cstdio>

typedef unsigned long long ull;

const int N = 2e3 + 5;
const int threshold=10000000;

ull k1,k2;
ull Rand(){
  ull k3=k1,k4=k2;
  k1=k4;
  k3^=(k3<<23);
  k2=k3^k4^(k3>>17)^(k4>>26);
  return k2+k4;
}

int n, m, a[N],b[N]; //数组 a 和 b
ull f[N][N * 3];

inline void gen(int n,ull _k1,ull _k2){
  k1=_k1,k2=_k2;
  for(int i=1;i<=n;i++){
    a[i]=Rand()%threshold+1;
    b[i]=Rand()%threshold+1;
  } 
}

int main() {
  freopen("hand.in", "r", stdin);
  freopen("hand.out", "w", stdout);
  
  scanf("%d%d%llu%llu", &n, &m, &k1, &k2);
  gen(n, k1, k2);
  for (int i = 1; i <= n; ++i) {
    int val = a[i];
    for (int j = 1; j <= 3; ++j) {
      for (int k = 0; k <= m; ++k) {
        f[i][k] = std::max(f[i][k], f[i - 1][k]);
        if (k >= j) f[i][k] = std::max(f[i][k], f[i - 1][k - j] + val);
      }
      if (j == 1) val += b[i];
      else if (j == 2) val += a[i];
    }
  }
  ull ans = 0;
  for (int i = 1; i <= m; ++i) {
    ans ^= f[n][i];
  }
  printf("%llu", ans);
  return 0;
}
